//
//  ViewController.swift
//  JuSwift
//
//  Created by Juvid on 2017/6/29.
//  Copyright © 2017年 Juvid. All rights reserved.
//

import UIKit
import SwiftUI

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{

    var ju_table : UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        testClass()
        _ = JuSwift5.init()
        JuModel.init().juStart()
        JuFunc.init().Jutest()
        JuHelloSwift.init().juTest()
        ju_table = UITableView.init(frame: self.view.bounds, style: .grouped)
        self.view.addSubview(ju_table)
        ju_table.delegate=self;
        ju_table.dataSource=self
        ju_table.rowHeight = 45
        
        //当设置为true时，如果有没处理的点击手势就会隐藏和现实navigationBar
//        self.navigationController?.hidesBarsOnTap = true
        //当设置为true时，滑动手势就会隐藏和现实navigationBar（左隐藏右显示）
        self.navigationController?.hidesBarsOnSwipe = true
//        //当设置为true时，横向方向时隐藏NavigationBar
//        self.navigationController?.hidesBarsWhenVerticallyCompact = true
//        //当设置为true时，键盘出现时隐藏NavigationBar
//        self.navigationController?.hidesBarsWhenKeyboardAppears = true
//        let juview = JuButtonView.init(frame: CGRect.init(x: 100, y: 100, width: 100, height: 100))
//        juview.backgroundColor = UIColor.red
//        self.view.addSubview(juview)
//        print(juview.titileLable)
        // Do any additional setup after loading the view, typically from a nib.
    }
    func testClass() {
        let testModel = JuNextModel.init()
        testModel.testInit()
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        if cell == nil {
            cell = UITableViewCell.init(style: .default, reuseIdentifier: "cell")
        }
        cell!.contentView.backgroundColor = UIColor.red
        cell?.textLabel?.text = "这是一个tableCell"
        return cell!
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.section == 0 {
            let alrt = UIAlertController.init(title: "hello", message: "你点击了第\(indexPath.section) section,第\(indexPath.row) row", preferredStyle: .alert)
            let actionTrue = UIAlertAction.init(title: "确定", style: .default) { (action) in
                print(action.title!)
            }
            alrt .addAction(actionTrue)
            self.present(alrt, animated: true, completion: nil)
        }

        if indexPath.section == 1 {
            let vc = UIHostingController(rootView: SwiftUIView())
            self.navigationController?.present(vc, animated: true, completion: nil)
        }


    }
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath){
        if indexPath.row==0 {
            let maskPath = UIBezierPath.init(roundedRect: cell.bounds, byRoundingCorners:UIRectCorner(rawValue: UIRectCorner.topRight.rawValue|UIRectCorner.topLeft.rawValue), cornerRadii: CGSize.init(width: 8, height: 8))
            let maskLayer = CAShapeLayer.init()
            maskLayer.frame = cell.bounds
            maskLayer.path = maskPath.cgPath
            cell.contentView.layer.mask = maskLayer

        }else if(indexPath.row==9){
            let maskPath = UIBezierPath.init(roundedRect: cell.bounds, byRoundingCorners: UIRectCorner(rawValue: UIRectCorner.bottomLeft.rawValue|UIRectCorner.bottomRight.rawValue), cornerRadii: CGSize.init(width: 8, height: 8))
            let maskLayer = CAShapeLayer.init()
            maskLayer.frame = cell.bounds
            maskLayer.path = maskPath.cgPath
            cell.contentView.layer.mask = maskLayer

        }else{
            cell.contentView.layer.mask = nil
        }

    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

